package Demo;

import java.util.Arrays;

//增删查改
public class MyArray {
    int DEFAULT_SIZE = 5;
    int[] elem = new int[DEFAULT_SIZE];
    int UsedSize;
    public boolean isFull(){
        if (UsedSize >= elem.length){
            return true;
        }
        return false;
    }
    public void Expansion(){
        this.elem = Arrays.copyOf(elem,2*elem.length);
    }
    public void addLast(int added){//添加新数据到尾部
        if (isFull()){
            Expansion();
        }
        this.elem[UsedSize] = added;
        UsedSize++;
    }
    public void add(int pos,int val){//在指定位置添加新数据
        if (isFull()){
            Expansion();
        }
        for (int i = UsedSize;i >= pos; i--){
            elem[i] = elem[i-1];
        }
        elem[pos-1] = val;
        UsedSize++;
    }
    public void delete(int pos){//删除指定位置的数据
        for (int i = pos;i<=UsedSize;i++){
            elem[i-1] = elem[i];
        }
        UsedSize--;
    }
    public int find(int toFind){
        for (int i = 0;i < UsedSize;i++){
            if (elem[i] == toFind){
                return 1;
            }
        }
        return -1;
    }
    public void change(int Number){

    }

}
